package com.hdoit.ares.logical.share.service.impl;

import java.util.Calendar;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.acc.service.IGoldenBeanDetailService;
import com.hdoit.ares.logical.share.dao.IConsultDao;
import com.hdoit.ares.logical.share.model.Consult;
import com.hdoit.ares.logical.share.service.IConsultService;
import com.hdoit.ares.selfcommon.enums.acc.GoldenBeanType;
import com.hdoit.ares.selfcommon.enums.acti.TaskId;
import com.tennetcn.common.dao.base.impl.SuperService;
import com.tennetcn.common.enums.ModelStatus;
import com.tennetcn.common.utils.CommonUtils;
import com.tennetcn.common.utils.DateUtils;
/**
 * @author      caochengmeng
 * @email       
 * @createtime  2018年03月25日 16:17:53
 * @comment
 */
@Component
public class ConsultServiceImpl extends SuperService<Consult> implements IConsultService{
	
	private IGoldenBeanDetailService goldenBeanDetailService;
	private IConsultDao consultDao;
	
	
	public IGoldenBeanDetailService getGoldenBeanDetailService() {
		return goldenBeanDetailService;
	}
	@Resource
	public void setGoldenBeanDetailService(IGoldenBeanDetailService goldenBeanDetailService) {
		this.goldenBeanDetailService = goldenBeanDetailService;
	}
	public IConsultDao getConsultDao() {
		return consultDao;
	}
	@Resource
	public void setConsultDao(IConsultDao consultDao) {
		this.consultDao = consultDao;
	}
	
	@Override
	public int queryCountDayShares(String customerId) {
		return consultDao.queryCountDayShares(customerId);
	}
	@Override
	public int queryCountMonthShares(String month, String customerId) {
		return consultDao.queryCountMonthShares(month, customerId);
	}
	@Override
	public boolean queryCountIsDayShare(String customerId) {
		if(queryCountDayShares(customerId)>=1){
			return true;
		}
		return false;
	}
	@Override
	public boolean queryCountIsMonthShare(String month,String customerId) {
		if(queryCountMonthShares(month, customerId)>=15){
			return true;
		}
		return false;
	}
	
	@Override
	public boolean setConsult(String shareId, String shareType, String customerId) {
		Consult consult = new Consult();
		consult.setId(CommonUtils.getKeyId());
		consult.setCustomerId(customerId);
		consult.setShareId(shareId);
		consult.setShareType(shareType);
		consult.setCreateTime(DateUtils.getCurrent());
		consult.setModelStatus(ModelStatus.add);
		if (applyChange(consult)) {
			if(queryCountDayShares(customerId)==1){
				if(goldenBeanDetailService.addGoldenBeanDetail(TaskId.dayShare, 20, GoldenBeanType.dayShare, customerId)){
					return true;
				}
			}
			Calendar cal = Calendar.getInstance();
			//获取当前日期月份
		    String month = String.valueOf(cal.get(Calendar.MONTH) + 1);
			if(queryCountMonthShares(month, customerId)==15){
				if(goldenBeanDetailService.addGoldenBeanDetail(TaskId.monthShare, 2000, GoldenBeanType.monthShare, customerId)){
					return true;
				}
			}
		}
		return false;
	}

}